
import Li from "./list.js"
import store from "../../store/store.js"




export default React.createClass({
	 componentWillMount:function(){
	 	//加载前获取name名字,然后请求
	 	 var shi = this.props.params.name.indexOf("=")+1
	 	 var Namekey = this.props.params.name.slice(shi)
	 	 var url = "http://www.chawo.com/mobile/index.php?act=goods&op=goods_list&keyword="+Namekey+"&page=100&curpage=3&keyword=&callback=jsonp3"
	 	 store.dispatch(function(dispatch , state){
                $.ajax({
				async: false,
				url: url,
				type: "GET",
				dataType: 'jsonp',
				success: function(data) {
					   dispatch({
                        type : "GOODS_LIST",
                        content : data
                   }) 
				}
			}) 
}) 
 }, 
 	getInitialState : function(){
 		return {
 			goods_list:[]
 		}
 	},
 	updateView(){ //此处为提供的更新视图方法
        var newData = store.getState(); 
        this.setState(
              {
              	goods_list :newData.list.goods_list
              }
        )
   },
   removeSubscribe : null,
    componentWillUnmount(){ 
        this.removeSubscribe();
    },
 componentDidMount:function(){
 	this.removeSubscribe= store.subscribe(this.updateView);
 	var that =this
// 	setTimeout(function(){
// 		//console.log(that.state)
// 	},1000)
 },
	render:function(){
		return (
				<Li data={this.state.goods_list}/>
			)
	}
})
